package com.yanqu.road.server.cmd.monopolymarket.rank;

import com.yanqu.road.entity.monopolymarket.resgrab.MonopolyMarketResGrabFinishData;
import com.yanqu.road.pb.monopolymarket.MonopolyMarketProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.monopolymarket.MonopolyMarketResGrabMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description
 * @Author cwq
 * @Data 2021/9/6 20:14
 */
@Cmd(code = Protocol.C_CROSS_MONOPOLY_MARKET_ADD_RANK_VALUE_SUCCESS, desc = "榷场回调给跨服 排行榜数值加成功")
public class CrossMonopolyMarketAddRankValueSuccessCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        MonopolyMarketProto.MonopolyMarketAddRankValueToCrossReqMsg gameMsg = MonopolyMarketProto.MonopolyMarketAddRankValueToCrossReqMsg.parseFrom(packet.getBytes());
        List<MonopolyMarketResGrabFinishData> list = new ArrayList<>();
        synchronized (MonopolyMarketResGrabMgr.userResGrabRankMap) {
            for (long id : gameMsg.getIdList()) {
                MonopolyMarketResGrabFinishData item = MonopolyMarketResGrabMgr.userResGrabRankMap.remove(id);
                if (item != null) {
                    item.setIsJoinRank(true);
                    list.add(item);
                }
            }
        }
        synchronized (MonopolyMarketResGrabMgr.tempResGrabFinishList) {
            MonopolyMarketResGrabMgr.tempResGrabFinishList.addAll(list);
        }
    }

    @Override
    public void sendData() {

    }

}
